package com.itheima.controller;

import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.entity.Student;
import com.itheima.entity.StudentQueryParam;
import com.itheima.service.EmpService;
import com.itheima.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @GetMapping
    public Result list(StudentQueryParam studentQueryParam){
        log.info("查询参数：{}", studentQueryParam);
        PageBean pageBean = studentService.list(studentQueryParam);
        return Result.success(pageBean);
    }
    @PostMapping
    public Result save(@RequestBody Student student){
        log.info("保存学生信息：{}", student);
        studentService.save(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        log.info("查询学生信息，参数：{}", id);
        Student student = studentService.getInfo(id);
        return Result.success(student);
    }

    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改学生信息：{}", student);
        studentService.update(student);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable("ids")List<Integer> ids){
        log.info("删除学生信息，参数：{}", ids);
        studentService.deleteByIds(ids);
        return Result.success();
    }

    @PutMapping("violation/{id}/{score}")
    public Result updateScore(@PathVariable("id") Integer id, @PathVariable("score") Short score){
        log.info("修改学生信息：{}", id);
        studentService.updateScore(id, score);
        return Result.success();
    }
}
